{% extends "base.html" %}

{% block head %}
    <link rel="stylesheet" href="{{ theme_asset(request, 'css/qa.css') }}">
{% endblock head %}

{% block title %}{{ qa_config.qa_title }}{% endblock title %}
{% block subtitle %}{{ qa_config.qa_title }}{% endblock subtitle %}

{% block content %}
{% set query_params = request.query_params %}
    {% if qa_config.qa_content_head %}
        {{ qa_config.qa_content_head|safe }}
    {% endif %}

    <div id="bo_list" class="position-relative">
        <!-- 开始一个类别 { -->
        <nav id="bo_cate" class="my-5">
            <h2 class="blind">{{ qa_config.qa_title }} 类别</h2>
            <ul id="bo_cate_ul">
                <li class="d-inline-block p-1 main-font fs-5"><a href="{{ request.url.replace_query_params() }}" {% if not query_params.sca %}id="bo_cate_on" class="main-bg text-white"{% endif %}>已满</a></li>
                {% for category in categories %}
                <li class="d-inline-block p-1 main-font fs-5"><a href="{{ request.url.replace_query_params(sca=category) }}" {% if query_params.sca == category %}id="bo_cate_on" class="main-bg text-white"{% endif %}>{{ category }}</a></li>
                {% endfor %}
            </ul>
        </nav>
        <!-- } 类别结束 -->                                                          
        <!-- 公告板页面信息和按钮启动 { -->
        <div id="bo_btn_top" class="my-3">
            <div id="bo_list_total">
                <span>Total {{ total_count|number_format }}枪</span>
                {{ current_page|number_format }} 页数
            </div>
            <ul class="btn_bo_user">
                {% if request.state.is_super_admin %}
                <li>
                    <a href="{{ url_for('qa_config_form') }}" class="btn_admin btn" title="经理">
                        <i class="fa fa-cog fa-spin fa-fw"></i>
                        <span class="blind">经理</span>
                    </a>
                </li>
                {% endif %}
                <li>
                    <button type="button" class="btn_bo_sch btn_b01 btn fs-4" title="公告板搜索">
                        <i class="fa fa-search" aria-hidden="true"></i>
                        <span class="blind">公告板搜索</span>
                    </button>
                    <!-- 开始搜索公告板 -->
                    <div class="bo_sch_wrap w-100 h-100 fixed-top" style="z-index:9999;">
                      <fieldset class="bo_sch position-absolute top-50 start-50 wrapper-bg shadow-lg main-border rounded-4 overflow-y-auto" style="width:330px; max-height:300px;">
                            <h3>搜索</h3>
                            <legend class="bg-danger">搜索帖子</legend>
                            <form name="fsearch" method="get" class="d-block p-4">
                                <input type="hidden" name="sca" value="{{ query_params.sca }}">
                                <input type="hidden" name="sop" value="{{ query_params.sop|default("or") }}">
                                <label for="sfl" class="blind">搜索目标</label>
                                <select name="sfl" id="sfl" class="w-100 input-border input-bg main-font rounded-1 fs-5" style="height: 40px;">
                                    <option value="qa_subject" {{ get_selected(query_params.sfl, 'qa_subject') }}>标题</option>
                                    <option value="qa_content" {{ get_selected(query_params.sfl, 'qa_content') }}>内容</option>
                                    <option value="qa_name" {{ get_selected(query_params.sfl, 'qa_name') }}>作家</option>
                                    <option value="mb_id" {{ get_selected(query_params.sfl, 'mb_id') }}>会员Id</option>
                                </select>
                                <label for="stx" class="blind">搜索词<strong class="blind"> 必不可少的</strong></label>
                                <div class="sch_bar d-inline-block w-100 mt-4 input-border input-bg main-font rounded-1 fs-5">
                                    <input type="text" name="stx" value="{{ query_params.get("stx", "") }}" id="stx" required="" class="sch_input border-0 bg-transparent px-1 main-font" style="width: 250px;height: 38px;" size="25" maxlength="15" placeholder=" 请输入您的搜索词">
                                    <button type="submit" value="搜索" class="sch_btn sub-font bg-transparent border-0 fs-4" style="width: 40px;height: 38px;" title="搜索">
                                        <i class="fa fa-search" aria-hidden="true"></i>
                                        <span class="blind">搜索</span>
                                    </button>
                                </div>
                                <button type="button" class="bo_sch_cls">
                                    <i class="fa fa-xmark" aria-hidden="true"></i>
                                    <span class="blind">关闭</span>
                                </button>
                            </form>
                        </fieldset>
                        <div class="bo_sch_bg bg-black bg-opacity-10 w-100 h-100"></div>
                    </div>
                    <!-- 公告板搜索结束 -->
                </li>
                <li>
                    <a href="{{ url_for('qa_form_write') }}?{{ query_params }}" class="btn_b01 btn" title="登记入伍人员">
                        <i class="fa fa-pencil" aria-hidden="true"></i>
                        <span class="blind">登记入伍人员</span>
                    </a>
                </li>
            </ul>
        </div>
        <!-- } 公告板页面信息和按钮结束 -->
        <form name="fqalist" id="fqalist" action="{{ url_for('qa_delete_list') }}?{{ query_params }}" onsubmit="return fqalist_submit(this);" method="post">
            <input type="hidden" name="token" value="">
                    
            <div class="tbl_head01 tbl_wrap">
                <table>
                <caption>列表</caption>
                <thead>
                <tr>
                    <th scope="col" class="all_chk chk_box">
                        <input type="checkbox" id="chkall" onclick="if (this.checked) all_checked(true); else all_checked(false);" class="selec_chk">
                        <label for="chkall">
                            <span>&nbsp;</span>
                            <b class="blind">当前页面帖子的完整选择</b>
                        </label>
                    </th>
                    <th scope="col">编号</th>
                    <th scope="col">标题</th>
                    <th scope="col">作家</th>
                    <th scope="col">注册日</th>
                    <th scope="col">状态</th>
                </tr>
                </thead>
                    <tbody>
                    {% for qa in qa_list %}
                        <tr class="{{ loop.cycle('', 'even') }}">
                            <td class="td_chk chk_box">
                                <input type="checkbox" name="chk_qa_id[]" value="{{ qa.qa_id }}" id="chk_qa_id_{{ loop.index }}" class="selec_chk">
                                <label for="chk_qa_id_{{ loop.index }}">
                                    <span>&nbsp;</span>
                                    <b class="blind">{{ qa.subject }}</b>
                                </label>
                            </td>
                            <td class="td_num">{{ qa.num }}</td>
                            <td class="td_subject">
                                <span class="bo_cate_link">{{ qa.qa_category }}</span>
                                <a href="{{ url_for('qa_view', qa_id=qa.qa_id) }}?{{ query_params }}" class="bo_tit d-block main-font fw-bold">
                                    {{ qa.subject|search_font(query_params.get("stx", ""))|safe }}
                                    {% if qa.icon_file %}<i class="fa fa-download" aria-hidden="true"></i>{% endif %}
                                </a>
                            </td>
                            <td class="td_name">{{ qa.qa_name }}</td>
                            <td class="td_date">{{ qa.qa_datetime }}</td>
                            <td class="td_stat">
                                {% if qa.qa_status %}
                                    <span class="txt_done">完成答案</span>
                                {% else %}
                                    <span class="txt_rdy">等待答案</span>
                                {% endif %}
                            </td>
                        </tr>
                    {% else %}
                        <tr><td colspan="6" class="empty_table">Q&A没有列表.</td></tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
            <!-- 页数 -->
            {{ paging|safe }}
            <!-- 页数 -->
            <div class="bo_fx">
                <ul class="btn_bo_user">
                    {% if request.state.is_super_admin %}
                    <li>
                        <button type="submit" name="btn_submit" value="删除所选内容" title="删除所选内容" onclick="document.pressed=this.value" class="btn btn_b01 btn_admin fs-4">
                            <i class="fa fa-regular fa-trash-can" aria-hidden="true"></i>
                            <span class="blind">删除所选内容</span>
                        </button>
                    </li>
                    {% endif %}
                    <li>
                        <a href="{{ url_for('qa_list') }}" class="btn_b01 btn" title="列表">
                            <i class="fa fa-list" aria-hidden="true"></i>
                            <span class="blind">列表</span>
                        </a>
                    </li>
                    <li>
                        <a href="{{ url_for('qa_form_write') }}" class="btn_b01 btn" title="登记入伍人员">
                            <i class="fa fa-pencil" aria-hidden="true"></i>
                            <span class="blind">登记入伍人员</span>
                        </a>
                    </li>
                </ul>
            </div>
        </form>
    </div>
    <script>
        // 公告板搜索
        // 게시판 검색
        $(".bo_sch_wrap").hide();

        $(".btn_bo_sch").on("click", function() {
            $(".bo_sch_wrap").toggle();
        })
        $('.bo_sch_bg, .bo_sch_cls').click(function(){
            $('.bo_sch_wrap').hide();
        });

        function all_checked(sw) {
            var f = document.fqalist;
        
            for (var i=0; i<f.length; i++) {
                if (f.elements[i].name == "chk_qa_id[]")
                    f.elements[i].checked = sw;
            }
        }

        function fqalist_submit(f) {
            var chk_count = 0;
        
            for (var i=0; i<f.length; i++) {
                if (f.elements[i].name == "chk_qa_id[]" && f.elements[i].checked)
                    chk_count++;
            }
        
            if (!chk_count) {
                alert(document.pressed + "选择您想要的一个或多个帖子.");
                return false;
            }
        
            if(document.pressed == "删除所选内容") {
                if (!confirm("是否确实要删除所选帖子?\n\n您无法恢复一次删除的材料"))
                    return false;
            }

            f.token.value = generate_token();

            return true;
        }
    </script>

    {% if qa_config.qa_content_tail %}
        {{ qa_config.qa_content_tail|safe }}
    {% endif %}
{% endblock content %}